package io.springboot.jpa.examples.springbootjpaexamples.model;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author yzc
 * @description
 * @date 2018/9/7
 */
@Entity
@Table(name = "menu")
public class Menu extends BaseBean implements Serializable {
    private static final long serialVersionUID = 1217789344061877552L;
    private String name;
    private String url;
    private long parentId;
    private int sort;
    private List<Role> roleList = new ArrayList<>();
    private Menu superior;
    private List<Menu> subsets = new ArrayList<>();

    @Column(name = "name", length = 10, unique = true)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "url", length = 50)
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Column(name = "parent_id")
    public long getParentId() {
        return parentId;
    }

    public void setParentId(long parentId) {
        this.parentId = parentId;
    }

    @JsonIgnore
    @ManyToMany
    @JoinTable(name = "role_menu", joinColumns = {@JoinColumn(name = "menu_id")}, inverseJoinColumns = {@JoinColumn(name = "role_id")})
    public List<Role> getRoleList() {
        return roleList;
    }

    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }

    @Column(name = "sort", length = 1)
    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    @JsonIgnore
    @Transient
    public Menu getSuperior() {
        return superior;
    }

    public void setSuperior(Menu superior) {
        this.superior = superior;
    }

    @Transient
    public List<Menu> getSubsets() {
        return subsets;
    }

    public void setSubsets(List<Menu> subsets) {
        this.subsets = subsets;
    }
}
